refactor: extract shared AI API logic into useAIFetch composable#1439
Merged
refactor: extract shared AI API logic into useAIFetch composable#1439
Conversation
Member
yanglbme
commented
Apr 6, 2026
- Add useAIFetch composable with buildAIHeaders, resolveEndpointUrl, fetchSSE (streaming), and fetchJSON (non-streaming) utilities
- Refactor AIConfig and AIImageConfig to use shared header/URL/fetch helpers
- Refactor AIAssistantPanel to use fetchSSE for stream parsing
- Add useAIFetch composable with buildAIHeaders, resolveEndpointUrl,
fetchSSE (streaming), and fetchJSON (non-streaming) utilities
- Refactor AIConfig and AIImageConfig to use shared header/URL/fetch
helpers
- Refactor AIAssistantPanel to use fetchSSE for stream parsing
- Refactor ToolBoxPopover to use fetchSSE for stream parsing
- Merge duplicate generateImage/regenerateWithPrompt into single
doGenerateImage in AIImageGeneratorPanel
- Remove ~190 lines of duplicated code across 5 components
|
🚀 Surge Preview has been successfully deployed! Preview URL: https://doocs-md-preview-pr-1439.surge.sh Built with commit 258cba7 |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the web app’s AI integration by extracting shared request header building, endpoint URL resolution, and streaming/non-streaming fetch helpers into a new useAIFetch composable, then updating the AI chat/image UI to use the shared utilities.
Changes:
- Added
useAIFetchwithbuildAIHeaders,resolveEndpointUrl,fetchSSE, andfetchJSON. - Refactored AI chat/image config “test connection” flows to use shared header/URL +
fetchJSON. - Refactored streaming chat/toolbox flows to use
fetchSSEand centralize SSE parsing.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/web/src/composables/useAIFetch.ts | New shared AI fetch utilities (headers, endpoint normalization, SSE + JSON fetch helpers). |
| apps/web/src/components/ai/tool-box/ToolBoxPopover.vue | Uses shared header/URL helpers and fetchSSE for streaming toolbox actions. |
| apps/web/src/components/ai/image-generator/AIImageGeneratorPanel.vue | Reuses shared header/URL helpers and consolidates image generation logic. |
| apps/web/src/components/ai/image-generator/AIImageConfig.vue | Uses shared header/URL helpers and fetchJSON for connection testing. |
| apps/web/src/components/ai/chat-box/AIConfig.vue | Uses shared header/URL helpers and fetchJSON for connection testing. |
| apps/web/src/components/ai/chat-box/AIAssistantPanel.vue | Uses shared header/URL helpers and fetchSSE for streaming response parsing. |
|
🚀 Cloudflare Workers Preview has been successfully deployed! Preview URL: https://md-pr-1439.doocs.workers.dev Built with commit 258cba7 |
|
🗑️ Cloudflare Workers preview deployment has been cleaned up. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.